// JavaScript Document
$(document).ready(function() {


  
	    $("#logbtn").click(function(){
		 login($("#userid").val(),$("#password").val(),$("#gurl").val());
		})  
		 
	 
	  $("#logbtn1").click(function(){
		//alert("dd");
		login1();
	
		});
		$("body").keydown(function(){
				if (event.keyCode==13)  {
        login1();  
      }
			
			})
	  

		
	  
	    $("#regbtn").click(function(){
		reg();
	
		});
	  
	  
	   changemsg();
			 	
		});




function login(userid,password,gurl){
	if(userid==""){
		$("#ts").empty();	
		  $("#ts").html("账号为空，请填写！");
		  return;
		}
			if(password==""){
		$("#ts").empty();	
		  $("#ts").html("密码为空，请填写！");
		  return;
		}
	$.ajax({ 
        type: "POST", 
        url: "inc/login_inc.php", 
        dataType: "text", 
        data: {"btn":true,"userid":userid,"password":password,"gurl":gurl}, 
        beforeSend: function(){ 
      
        }, 
 success: function(data){
 
  if(data.indexOf("userid or password is wrong")!=-1){
	  $("#ts").empty();	
    $("#ts").html("账号或者密码错误，请重新输入！");
	  return;
 }
	  
	   
  if(data.indexOf("login is ok")!=-1){
	    $("#ts").empty();
	if($("#gurl").val()!=""){
		location.href=$("#gurl").val();
		}
		else{
			
		top.location.href="index.php";	
			}
	  
return;
	  }
  if(data.indexOf("gylog is ok")!=-1){
  top.location.href="index.php";
 }  
	  
 }
 
		 })
}
		
function login1(){

	if($("#userid").val()=="" || $("#userid").val()=="请输入您的账号"){
			alert("账号不能为空");
			 
			$("#userid").focus();
	       return;
			}
	if($("#password").val()==""){
			alert("密码不能为空");
			$("#password").focus();
	       return;
			}
$.ajax({ 
        type: "POST",
        url: "inc/login_inc.php", 
        dataType: "text", 
        data: {"logbtn":"true","userid":$("#userid").val(),"password":$("#password").val(),gourl:$("#gourl").val()}, 
        beforeSend: function(){ 
         
        }, 
 success: function(data){ 
//alert(data);
 if(data.indexOf("userid or password is wrong")!=-1){
  alert("账号或者密码不正确");
	       return;
 
 }
  if(data.indexOf("login is ok")!=-1){
   
			tx=data.split(",");
			var userno=tx[1];
			var password=tx[2];
		//top.location.href="index.php";
		alert("对不起，你没有权限进入后台");
	    return;
			
 }
  if(data.indexOf("gylog is ok")!=-1){
  top.location.href="./cpgl/index.php";
 }
 
}
})

}


function reg(){
	
		if($("#email").val()=="" || $("#email").val()=="请输入您的邮箱"){
			 $("#regmsg").html("用户邮箱不能为空").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#email").focus();
	       return;
			}
			
		if($($("#email").val()==""||"#email").val()!="" && !/.+@.+\.[a-z A-Z]{2,4}$/.test($("#email").val())){
				 $("#regmsg").html("邮箱格式不正确").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#email").focus();
	       return;
			
			
			}	
		
	
	   if($("#userid").val()=="" || $("#userid").val()=="请输入您的账号"){
			 $("#regmsg").html("用户名不能为空").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#userid").focus();
	       return;
			}
	if($("#password").val()=="" ){
			 $("#regmsg").html("密码不能为空").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#password").focus();
	       return;
			}
		if($("#c_password").val()=="" ){
			 $("#regmsg").html("确认密码不能为空").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#c_password").focus();
	       return;
			}	
		if($("#password").val()!=$("#c_password").val() ){
			 $("#regmsg").html("确认密码不正确").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			$("#password").focus();
	       return;
			}
			if($('#agree:checked').length==0){
			 $("#regmsg").html("您还没同意应用商城条款").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
			
	       return;
			}	
		$.ajax({ 
        type: "POST",
        url: "inc/login_inc.php", 
        dataType: "text", 
        data: {"regbtn":"true","userid":$("#userid").val(),"password":$("#password").val(),"email":$("#email").val(),gourl:$("#gourl").val()}, 
        beforeSend: function(){ 
         
        }, 
 success: function(data){ 
 if(data.indexOf("userid is exit")!=-1){
  $("#regmsg").html("该用户已经存在").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
	       return;
 
 }
  if(data.indexOf("reg is ok")!=-1){
	 // alert(data);
   	tx=data.split(",");
			var userno=tx[1];
			var password=tx[2];
		top.location.href="http://store.job688.net/uc_center.php?userno="+userno+"&password="+password+"&yyshop=1";
 }
 
   if(data.indexOf("reg no")!=-1){
     $("#regmsg").html("未知原因导致注册不成功，请联系管理员").css("color","#f00").fadeTo(600,1);
			 setTimeout("$('#regmsg').fadeTo(600,0)",1500);
	       return;
 
 }
}
})
	
			
			
			
			
   }


function changemsg(){
	 $.ajax({ 
        type: "POST", 
        url: "inc/login_inc.php", 
        dataType: "json", 
        data: { "show":"true"}, 
        beforeSend: function(){ 
      }, 
 success: function(json){ 
 if(json.userid!="" ){
  $("#grzx").html("您好,<a href='javascript:;'>"+json.username+"</a>| <a href='inc/logout.php'>退出</a>");
 //alert(json.username);
 }
 }
 })
 }
